<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="/WEB-INF/tlds/spring.tld"%>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld"%>
<%@ taglib prefix="fn" uri="/WEB-INF/tlds/fn.tld"%>
<%@ taglib prefix="fmt" uri="/WEB-INF/tlds/fmt.tld"%>
<c:set var="BasePath" value="${pageContext.request.contextPath}"></c:set>
<c:set var="Plugins" value="${pageContext.request.contextPath}/res/plugins"></c:set>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>采购单修改</title>
<link href="${Plugins}/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="${Plugins}/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/datepicker/WdatePicker.js" type="text/javascript"></script>
<script src="${Plugins}/jquery/jquery-1.3.2.min.js"	type="text/javascript"></script>
<script src="${Plugins}/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="${BasePath}/res/js/common/utils.js" type="text/javascript"></script>
<script type="text/javascript" src="${BasePath}/res/js/ligerCommon.js"></script>
<style type="text/css">
#searchbar{
	margin-bottom: 10px;
}
.navbar {
		height: 20px;
		border-bottom: #E6E6E6 solid 1px;
		line-height: 20px;
	}
.l-button-search{
	width: 50px;
	margin-left: 10px;
	padding-bottom: 2px;
	display: inline;
}
</style>
</head>
<body style="padding:6px; overflow:hidden;">
<div id="">
	<div class="navbar"><span>您当前的位置：采购管理 &gt;采购单管理 &gt;采购单修改 </span></div>
	<br/>
	<table width="100%" cellpadding="0" cellspacing="0" class="l-table-edit" style="TABLE-LAYOUT: fixed" >
	    <tr height="30">
	        <td class="l-table-edit-td">&nbsp;采购单号: ${po.poNo }</td>
	        <td class="l-table-edit-td">&nbsp;创建人员: ${po.createPerson}</td>
	        <td class="l-table-edit-td">&nbsp;创建时间: ${po.createTime }</td>
	        <td class="l-table-edit-td">&nbsp;采购状态: <c:choose>
	        		<c:when test="${po.poStatus == 0 }">
	        			待审核
	        		</c:when>
	        		<c:when test="${po.poStatus == -1 }">
	        			审核未通过
	        		</c:when>
	        		<c:when test="${po.poStatus == 1 }">
	        			已审核
	        		</c:when>
	        		<c:when test="${po.poStatus == 2 }">
	        			采购中
	        		</c:when>
	        		<c:when test="${po.poStatus == 3 }">
	        			入库中
	        		</c:when>
	        		<c:when test="${po.poStatus == 4 }">
	        			部分入库
	        		</c:when>
	        		<c:when test="${po.poStatus == 5 }">
	        			采购完成
	        		</c:when>
	        		<c:otherwise>
	        			&nbsp;
	        		</c:otherwise>
	        	</c:choose>
	        </td>
	    </tr>
	    <tr height="30">
	        <td class="l-table-edit-td">&nbsp;采购日期: ${po.foPurDate }</td>
	        <td class="l-table-edit-td">&nbsp;采购类型: 
	    		<c:choose>
	        		<c:when test="${po.purcType == 1 }">
	        			产品采购
	        		</c:when>
	        		<c:when test="${po.purcType == 2 }">
	        			样品采购
	        		</c:when>
	        		<c:when test="${po.purcType == 3 }">
	        			其他采购
	        		</c:when>
	        		<c:otherwise>
	        			&nbsp;
	        		</c:otherwise>
	        	</c:choose>				
			</td>
			<%-- <c:if test="${po.lastAuditPerson != null}">
			<td class="l-table-edit-td">&nbsp;审核人员: ${po.lastAuditPerson}</td>
	        </c:if>
	        <td class="l-table-edit-td">&nbsp;审核流程: 
	        	<c:choose>
	        		<c:when test="${po.curAuditPoint == 1 }">
	        			待采购主管处理
	        		</c:when>
	        		<c:when test="${po.curAuditPoint == 2 }">
	        			待采购总监及运营主管处理
	        		</c:when>
	        		<c:when test="${po.curAuditPoint == 3 }">
	        			待财务负责人处理
	        		</c:when>
	        		<c:when test="${po.curAuditPoint == 4 }">
	        			待总经理处理
	        		</c:when>
	        		<c:when test="${po.curAuditPoint == 99 }">
	        			已结束流程
	        		</c:when>
	        		<c:otherwise>
	        			&nbsp;
	        		</c:otherwise>
	        	</c:choose>	
			</td> --%>
	    </tr>
	</table>
	<br/>
		<input  type="button" id="submit" value="保存" class="l-button-search" style="margin-left: 730px;">&nbsp;&nbsp;&nbsp;&nbsp;<input  type="button" id="tests" value="取消" class="l-button-search" >
	<br/><br/>
</div>
<div id="maingrid6" style="margin:0; padding:0"></div>
  <div style="display:none;">
  <!-- g data total ttt -->
</div>
<script type="text/javascript">
    var grid6 = null;
    var showList = "${showList}";
    $(function () {
      if(showList.toLowerCase() != "auhis") {
    	  var columns = [
    	            { display: '货品编码', name: 'productNo', align: 'left', width: '10%'},
    	            { display: '商品名称', name: 'ppName', width: '12%'},
    	            { display: '箱包装规格', name: 'ppSpecification', width: '8%' },
    	            { display: '供应商名称', name: 'ppSupplierName', width: '10%' },
    	            { display: '仓库名称', name: 'ppWarehouseName', width: '8%'},
    	            { display: '出厂日期', name: 'manufactureTime',type: 'date', format: 'yyyy-MM-dd' },
    	            { display: '保质期天数', name: 'shelfLife',type: 'date', format: 'yyyy-MM-dd'}, 
    	            { display: '单价', name: 'salePrice', width: '8%' },
    	            { display: '最低采购数', name: 'buyNum', width: '8%', type:'int',editor: { type: 'int',maxValue:999999999,minValue:1},
    	            	render:function(rowdata, rowindex, value){
    	            		rowdata.buyNum  = showList[rowindex].buyNum=value;
    	            		return rowdata.buyNum;
    	            	}},
    	          /*   { display: '数量', name: 'ppNumber',type:'int',editor: { type: 'int',maxValue:999999999,minValue:1},
    	            	render:function(rowdata, rowindex, value){
    	            		var n = "<font style='color: blue;font-size: 12px;'>请输入数量</font>";
    	            		ppNumber = rowdata.ppNumber > 0 ? rowdata.ppNumber : 0;
    	            		if(value > 0 && ppNumber <= value){
    	            			value = parseInt(value,10);
    	            			n = rowdata.ppNumber = showList[rowindex].ppNumber = value;
    	            		}else{
    	            			showList[rowindex].ppNumber = rowdata.ppNumber = 0;
    	            		}
    	            		return n;
    	            	}
    	            },  */
    	            { display: '数量', name: 'ppNumber',type:'int',editor: { type: 'int',maxValue:999999999,minValue:1},
    	            	render:function(rowdata, rowindex, value){
    	            		if(rowdata.ppNumber>0 && rowdata.buyNum > rowdata.ppNumber){
    	            			rowdata.ppNumber = rowdata.ppNumber;
    	            		}else{
    	            			return rowdata.ppNumber =rowdata.buyNum ;
    	            		}
    	            		return rowdata.ppNumber;
    	            	}
    	            }, 
    	            { display: '成本价', name: 'ppUnitPrice',align: 'left', width: '8%', editor:{type:'float'}, render: function(rowdata, rowindex, value) {
    	            	/* return value.toFixed(2); */
    	            	return StringUtils.html_encode(value);
    	            } },
    	            
    	            { display: '采购总价',name:"totalPrice",
    	            	render:function(rowdata, rowindex, value){
    	            		if(rowdata.ppNumber != null && rowdata.ppUnitPrice != null){
    	            			var p = rowdata.ppNumber * rowdata.ppUnitPrice;
    	                		var num = new Number(p);
    	                		value = num.toFixed(2);
    	                		showList[rowindex].totalPrice = value;
    	            		}
    	            		if(value == null || value == "") value ="0.00";
    	            		rowdata.totalPrice = value; 
    	            		return value;
    	            	}	
    	        	},
    	            ];
    	 
        grid6 = $("#maingrid6").ligerGrid({
            columns: columns, 
            pageSize: 30,
            width: '100%',
            height: '100%',
            dataType: 'server', 
            dataAction: 'server',
            pagesizeParmName: 'pageSize',
            enabledEdit:true,
            parms: [
                    {name: "poNo", value:'${po.poNo }' }
            	],
            url: "ajaxToPoProductList.do"
        });
      }
        
    });
    
  //修改校验
 var prod = true;
 function valData() {
	 debugger;
 	prod = true;
 	
 	var header = {'ppNumber': '数量','ppUnitPrice': '供应商','purWhNo': '仓库'};
 	 
 	 $.each(showList,function(index,item){
 			if(item.ppNumber == 0){
 				debugger;
 				$.ligerDialog.warn("采购数量不能为空!");
 				prod = false;
 				return false;
 			}else if(item.ppNumber < item.buyNum ){
 				$.ligerDialog.warn("采购数量不能少于最低订货数量!");
 				prod = false;
 				return false;
 			}
 		
 			if(!prod) return prod;
 		}); 
 	
 }
    
    /**
     * 采购单商品单价及数量修改
     * @param rowindex
     */
     function modifyPriceAndQuantity(poNo, prodNo) {
     	var w = $.ligerDialog.open({ title: "采购商品单价及数量修改", url: 'toPoProdPriceAndQuantityModify.do?poNo=' + poNo + '&prodNo=' + prodNo, height: 400, width: 600, isResize: false, isDrag: false });
     	w.show();
     }
    /*显示采购单货品列表*/
   /*  function showPoProds(){
    	window.location.href="showPoDetail.do?poNo=${po.poNo}&showList=prods";
    } */
    
    /*回调*/
   /*  var parentTabId = ${tabId}; 
    var tabId = window.top.tab.getSelectedTabItemID();
    function operateSuccess(){
    window.top.tab.selectTabItem(parentTabId);
    window.top.tab.reload(parentTabId);
    window.top.tab.removeTabItem(tabId); 
    }*/
   
	$("#submit").click(function(){
		var items = new Array();
		var manager = $("#maingrid6").ligerGetGridManager();
		items =manager.getData();
		//校验
		$("form .l-text,.l-textarea").ligerHideTip();
		/* valData();
		if(!prod) return prod; */
		
		if(items.length>0){
			$.post(
					'update_purchase.do',
					{productlist:JSON.stringify(items),poNo:'${po.poNo }'},
					function(result) {
						if (result == 'success') {
							/* window.parent.f_tip('修改成功');
							window.location.reload(); */
							window.parent.f_tip('修改成功');
           					close_liger_tab();
						} else if (result == 'fail') {
							window.parent.f_tip('修改失败');
						}else{
							window.parent.f_tip(data);
						};
					}
			);
		}
	});
    // 取消
    $("#tests").click(function() {
    	close_liger_tab();
    });	
    
</script>
</body>
</html>